﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CAD.BLL;
using CAD.DTO;
using WFASmartketing.PRESENTACION_BASICOS;

namespace WFASmartketing.PRESENTACION_VENTAS
{
    public partial class AddCliente : Form
    {
        private PRESENTACION_VENTAS.RegistroVentas principal;
        private NewCliente cliente;
        public AddCliente(PRESENTACION_VENTAS.RegistroVentas principal)
        {
            InitializeComponent();
            this.principal = principal;
            this.cliente_selectByLikeTableAdapter.Fill(this.clienteGridDS.cliente_selectByLike, "%" + textBox1.Text + "%");
        }

        private void button2_Click(object sender, EventArgs e)
        {
             this.cliente_selectByLikeTableAdapter.Fill(this.clienteGridDS.cliente_selectByLike, "%" + textBox1.Text + "%") ;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                int id = (int)dataGridView1.CurrentRow.Cells[0].Value;
                cliente pro = clienteBLL.SelectByID(id);
                principal.cargarcliente(pro);
                this.Hide();
            }
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            if(cliente!=null){
                cliente.Hide();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.cliente_selectByLikeTableAdapter.Fill(this.clienteGridDS.cliente_selectByLike, "%" + textBox1.Text + "%");
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                int id = (int)dataGridView1.CurrentRow.Cells[0].Value;
                cliente pro = clienteBLL.SelectByID(id);
                principal.cargarcliente(pro);
                this.Hide();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            cliente= new NewCliente(principal,this);
            cliente.Show();
        }

        private void AddCliente_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (cliente != null)
            {
                cliente.Hide();
            }
        }
    }
}
